import { ref, computed } from "vue";
import { defineStore } from "pinia";
import { mapLayerEnum } from "@/enums";
import { LayerInfoType } from "@/types";

export const useMapLayerStore = defineStore("setting", () => {
  const mapType = ref<mapLayerEnum | "">("");
  const mapData = ref<Partial<Record<mapLayerEnum, Array<LayerInfoType>>>>();
  const currentMapData = computed(() => {
    if (mapType.value && mapData.value) {
      return mapData.value[mapType.value as mapLayerEnum] || [];
    }
    return [];
  });
  const setMapData = (key: mapLayerEnum, data: Array<LayerInfoType>) => {
    if (mapData.value?.[key]) {
      return;
    }
    if (mapData.value) {
      mapData.value[key] = data;
    } else {
      mapData.value = { [key]: data };
    }
  };
  const setMapType = (type: mapLayerEnum | "") => {
    if (mapType.value != type) {
      mapType.value = type;
    }
  };
  return { currentMapData, mapData, mapType, setMapType, setMapData };
});
